package com.init.linoj.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 编程语言枚举类
 */
public enum QuestionSubmitLanguageEnum {
    JAVA("java","java"),
    CPLUSPLUS("cpp","cpp"),
    GOLANG("go","go");

    private final String text;

    private final String value;

    QuestionSubmitLanguageEnum(String text,String value) {
        this.text=text;
        this.value=value;
    }

    /**
     * 获取值列表
     * @return List<String>
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item->item.value).collect(Collectors.toList());
    }

    /**
     * 根据value获取枚举值
     * @param value
     * @return QuestionSubmitLanguageEnum
     */
    public static QuestionSubmitLanguageEnum getEnumByValue(String value){
        if(ObjectUtils.isEmpty(value)){
            return null;
        }
        for(QuestionSubmitLanguageEnum anEnum : QuestionSubmitLanguageEnum.values()){
            if(anEnum.value.equals(value)){
                return anEnum;
            }
        }
        return null;
    }

    public String getText() {
        return text;
    }

    public String getValue() {
        return value;
    }
}
